package company.chubao;

import java.util.Scanner;

public class Chu4 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s1 = sc.nextLine();
        String s2 = sc.nextLine();
        if (s1.equals("") || s2.equals("")) {
            System.out.println(-1);
            return;
        }
        String[] array1 = s1.split(" ");
        String[] array2 = s2.split(" ");
        int min = Integer.MAX_VALUE;
        int n1 = array1.length;
        int n2 = array2.length;
        for (int i = 0; i < n1; i++) {
            for (int j = i + 1; j < n2; j++) {
                int m1 = Integer.parseInt(array1[i]);
                int m2 = Integer.parseInt(array2[j]);
                if (m1 + m2 != min) {
                    min = Math.min(min, m1 + m2);
                }
            }
        }
        System.out.println(min == Integer.MAX_VALUE ? -1 : min);
    }
}
